<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="mb-10">
        <div class="toplineBox">
          <div class="toplineBox-left">
            <el-select v-model="typeWages" placeholder="请选择工资模板" size="small" class="mr-10">
              <el-option
                v-for="item in listSelect"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
            <el-date-picker
              v-model="mouth"
              type="month"
              size="small"
              format="yyyyMM"
              value-format="yyyyMM"
              placeholder="选择月">
            </el-date-picker>
            <el-button type="primary" size="small" @click="searchFn('search')" class="ml-10"><i
              class="el-icon-search"></i>搜索
            </el-button>
            <el-button size="small" @click="refreshFn()"><i class="el-icon-refresh"></i>重置刷新</el-button>
          </div>
          <p class="numberline toplineBox-right">总{{page.total}}条</p>
        </div>
      </div>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStyle.tableStripe"
            :border="tableStyle.tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c"
          >
            <el-table-column
              label="姓名">
              <template slot-scope="scope">
                {{scope.row.user?scope.row.user.realname: ''}}
              </template>
            </el-table-column>
            <el-table-column
              label="岗位类型">
              <template slot-scope="scope">
                {{ scope.row.template ? scope.row.template.name : '' }}
              </template>
            </el-table-column>
            <el-table-column
              prop="month"
              label="月份">
            </el-table-column>
            <el-table-column
              prop="money"
              label="工资总额">
            </el-table-column>
            <el-table-column
              prop="update_time"
              label="创建时间">
            </el-table-column>
            <el-table-column
              label="操作">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="addStudent(scope.row)" plain>工资明细</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
          background
          layout="total, prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </div>
    <addWages :visible.sync="addvisible" @InitFn="InitFn"></addWages>
    <detailWages :visible.sync="detailvisible" :wagesDetail="wagesDetail"></detailWages>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import addWages from "./add"
import detailWages from "./detail"
import {
  wages_my_index,
  wagesTempList
} from "@/api/admin/wages"

export default {
  components: {
    addWages,
    detailWages
  },
  data () {
    return {
      arryList: [],
      typeWages:'',
      handleSelection: [],
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      detailVisible: false,
      editId: 0,
      mouth:'',
      addvisible: false,
      detailvisible: false,
      wagesDetail: null,
      list: {
        1: {
          id: 1,
          name: '编内'
        },
        2: {
          id: 2,
          name: '编外（外聘教师）'
        },
        3: {
          id: 3,
          name: '编外（生活老师）'
        },
        4: {
          id: 4,
          name: '编外（厨房）'
        },
        5: {
          id: 5,
          name: '编外（保安）'
        },
        6: {
          id: 6,
          name: '编外（补发）'
        }
      },
      listSelect: [
        {
          id: 1,
          name: '编内'
        },
        {
          id: 2,
          name: '编外（外聘教师）'
        },
        {
          id: 3,
          name: '编外（生活老师）'
        },
        {
          id: 4,
          name: '编外（厨房）'
        },
        {
          id: 5,
          name: '编外（保安）'
        },
        {
          id: 6,
          name: '编外（补发）'
        }
      ]
    }
  },
  created () {
    this.InitFn()
    this.InitTempFn()
  },
  methods: {
    // 工资模板初始化
    InitTempFn() {
        wagesTempList({
            p: 0
        }).then(res => {
            console.log('resss',res)
            this.listSelect = res.list.map((item)=>{
              return {
                id:item.id,
                name:item.name
              }
            })
        })
    },
    // 初始化
    InitFn () {
      wages_my_index({
        p: this.page.pageindex,
        month: this.mouth,
        template_id: this.typeWages
      }).then(res=>{
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    checkIdCard () {
      this.changeCartVisible = true
    },
    handleSelectionChange (val) {
      this.handleSelection = val
    },
    // 分页
    handleSizeChange (val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 刷新页面
    searchFn() {
      this.page.pageindex = 1
      this.InitFn()
    },
    // 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.typeWages = ''
      this.mouth = ''
      this.realname = ''
      this.InitFn()
    },
    addStudent (option) {
      this.wagesDetail = JSON.parse(JSON.stringify(option))
      this.detailvisible = true
    },
    detelFn (id, index) {
      let self_ = this
      this.$confirm('此角色将永久删除，该角色的用户将不再受此角色权限限制，确认删除此角色？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self_.$post(this.api.admin_role_detel, {
          id: id
        }).then((response) => {
          if (response.code === 0) {
            this.arryList.splice(index, 1)
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            this.$message.error(response.msg)
          }
        }).catch((err) => {
          console.log(err)
        })
      }).catch(() => {

      })
    }
  },
  mounted () {
  }
}
</script>
